package io.renren.modules.service.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.service.dao.ProductCodeDao;
import io.renren.modules.service.entity.ProductCodeEntity;
import io.renren.modules.service.service.ProductCodeService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("productCodeService")
public class ProductCodeServiceImpl extends ServiceImpl<ProductCodeDao, ProductCodeEntity> implements ProductCodeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProductCodeEntity> page = new Query<ProductCodeEntity>().getPage(params);
        List<Map<String, Object>> list = baseMapper.queryPage(params, page);
        return new PageUtils(list, (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
    }

    @Override
    public void insert(ProductCodeEntity productCode) {
        baseMapper.delete(null);
        productCode.setCreateTime(new Date());
        baseMapper.insert(productCode);
    }

    @Override
    public Map<String, Object> queryProductNameAndNumber() {
        return baseMapper.queryProductNameAndNumber();
    }

}
